package com.shop.controller;

import com.shop.entity.Cart;
import com.shop.entity.CartMaster;
import com.shop.entity.Result;
import com.shop.service.CartService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * description: 购物车action
 *
 * @author zhaoxiaozhao（xiaozhao.zhao@ucarinc.com）
 * @version 1.0
 * @date 2018/10/18 9:29
 **/
@Controller
@RequestMapping("/cart")
public class CartController {

    @Resource
    private CartService cartService;

    /**
     * description:<通过会员id显示出购物车>
     *
     * @author zhaoxiaozhao（xiaozhao.zhao@ucarinc.com）
     * @date   2018/10/18 9:32
     * @param   buyerId 会员id
     * @return 
     **/
    @RequestMapping("/showCart")
    public String showCart(String buyerId,ModelMap model){
        buyerId= "1";
          CartMaster cartMaster = cartService.showCart(buyerId);
          model.addAttribute("cartMaster",cartMaster);
          return "cart";
    }
    /**
     * description:<通过购物车id购物车中移除>
     *
     * @author zhaoxiaozhao（xiaozhao.zhao@ucarinc.com）
     * @date   2018/10/18 9:32
     * @param   cart 购物车id
     * @return
     **/
    @RequestMapping("/deleteCart")
    @ResponseBody
    public Result deleteCart(Cart cart){
        return cartService.deleteCart(cart);
    }
    /**
     * description:<添加购物车>
     *
     * @author zhaoxiaozhao（xiaozhao.zhao@ucarinc.com）
     * @date   2018/10/18 9:32
     * @param   cart 有商品id和商品数量
     * @return
     **/
    @RequestMapping("/addCart")
    @ResponseBody
    public Result addCart(Cart cart){
        cart.setBuyerId("1");
        return cartService.addCart(cart);
    }
    /**
     * description:<修改购物车商品数量>
     *
     * @author zhaoxiaozhao（xiaozhao.zhao@ucarinc.com）
     * @date   2018/10/18 9:32
     * @param   cart 有购物车id和商品数量
     * @return
     **/
    @RequestMapping("/udpateCartNumber")
    @ResponseBody
    public Result udpateCartNumber(Cart cart){
        return cartService.updateCartNumber(cart);
    }

}
